Borland Online And The Cobb Group Present:


July, 1995 - Vol. 2 No. 7

Borland C++ 4.x - C++ Quick Tips

While all Borland C++ users want to keep up on the latest C++ language features, we also need to keep our productivity high enough to stay gainfully employed. One way to save time using any programming tool is to take advantage of the small tips that save us a few moments here and there. After a while, those moments begin to accumulate.

With that thought in mind, here are three suggestions for improving your use of the Borland C++ Integrated Development Environment (IDE). Each tip, in its own way, will save you a little time­­and perhaps some head-scratching as well.

Programmer, brace yourself!

Of all the source-formatting conventions, probably none creates more arguments than the conventions dictating how you place braces ({ and }) in your code. As with most programming conventions, if you're consistent, you won't have any problems tracing the logic of your own code.

However, if you spend much time reading someone else's source files, you know how frustrating it can be to try to understand a complex function or expression written using a different formatting style. For example, when you're examining a series of if-then-else clauses or a complex switch statement, matching pairs of braces can be a tedious task.

However, if you're using the default keystroke mapping file, you can use the [Alt][[] key combination to locate the corresponding brace for a given brace in a pair. (By the way, pressing [Alt][]] has the same effect as pressing [Alt][[].)

To see how this works, open an editing window by choosing New from the File menu. When the new editing window appears, enter

void foo(int var)
{
  switch(var)
  {
    case 2:
    {
      boo();
    }
    default:
    {
      bar();
    } 
  }
}

Place the cursor at the beginning of line 2 and press [Alt][[]. The cursor will immediately move to the last line. Pressing [Alt][[] again will move the cursor back to line 2.

Experiment with placing the cursor ahead of any of the other opening or closing braces and then pressing [Alt][[]. Even though the formatting of the function in this example makes it easy to locate matching braces, you can use this key sequence to navigate complex expressions that use any brace-formatting style.

Opening up the Project window

If you use the IDE to manage your C++ development, you're no doubt familiar with the Project window. In general, the Project window displays the targets for each project, along with each target's source and library files, shown in hierarchical order.

By default, for each node you'll see a descriptive name and type that usually, but not always, is the same as the node's filename and extension. However, you can use the Project View page of the Environment Options dialog box to adjust the amount and type of information that the Project window will display for each node, as shown in Figure A.

Figure A - You'll use the Environment Options dialog box to adjust the amount of information that appears in the Project window.

Node better

First and foremost, you can configure the Project window to display a node for the project itself by selecting the Show Project Node check box. Even though adding a node for the project to the Project window doesn't affect the way the IDE processes the project, it's beneficial in a couple of ways.

If you display the project's node in the Project window, you'll find that it's much easier to rearrange executable targets and other nodes that are direct children of the project node. (These nodes appear as first-level nodes using the default Project window settings.)

In addition, if you display the project's node in the Project window, you may find it easier to understand which compiler options apply to all the files in the project and which apply to only a single node. (If you display the Local Options dialog box for the project's node, you'll see the same information that you see when you choose Project... from the Options menu.)

Running nodes

Another aspect of the default Project window view is that run-time library files, which automatically become part of the project, don't appear in the Project window. As you make changes to a target using the Target Expert dialog box, the IDE transparently changes which run-time files to include. You'll want to view these files if you need to find out which ones the linker will process when it creates the EXE file. Select the Show Run-Time Nodes check box to make these files visible.

Location, location, location

As we mentioned earlier, the default Project window view displays the name and type of each node. Since these are usually the same as the filename and extension of the node's file, you can display the node's path information instead. Doing so will show the full path to each file in the project instead of just showing each node's name and type.

Deselect the Name and Node Type check boxes and select the Location check box to display this information. Figure B shows a sample project's window using all the options we've described here.


Figure B - You can configure the Project window to display the project's node, run-time nodes, and full paths for each node's file.

Navigating errors

Few programmers can create a program of significant size that doesn't contain a few syntax errors. Whether it's a missing semi-colon at the end of a class declaration or a const pointer posing as a non-const parameter, small errors are bound to happen.

When you're ready to begin fixing these types of problems in your code, you may find that you're switching back and forth between the Message window and the editing windows many times before you've fixed all the errors. Instead of returning to the Message window to locate the source line that contains the next error or warning, you can skip directly to that line by using the Next Message and Previous Message commands.

For example, if you're editing a file that contains three errors, you can choose Next Message from the View menu (or press [Alt][F8]) to move immediately from the first error to the second. To move back to the previous error, simply choose Previous Message from the View menu (or press [Alt][F7]).

Return to the Borland C++ Developer's Journal index

Subscribe to the Borland C++ Developer's Journal


Copyright (c) 1996 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Publishing Company.